//
// itertool - a polynormial and type-safe iterator framework in C++.
//
// Copyright (c) 2021-2025 Feng Cong
//
// Distributed under the MIT Software License
// See accompanying file LICENSE.txt or copy at
// https://opensource.org/licenses/MIT

#include <itertool/itertool.h>

#include <cmath>
#include <numeric>
#include <vector>

#include "itertool_test.h"

TEST_CASE("Inclusion of itertool.h works") {
  auto sqrt_numbers = itertool::Map(itertool_test::NaturalNumber(10),
                                    [](int val) { return std::sqrt(val); });
  double sum =
      std::accumulate(sqrt_numbers.begin(), sqrt_numbers.end(), double(0));

  std::vector<double> data(10);
  std::iota(data.begin(), data.end(), 0);
  std::transform(data.begin(), data.end(), data.begin(),
                 [](double val) { return std::sqrt(val); });
  double sum2 = std::accumulate(data.begin(), data.end(), double(0));

  CHECK_EQ(sum, doctest::Approx(sum2));
}
